package com.demo.statemachine.d10;

import lombok.extern.slf4j.Slf4j;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State;

import java.util.Collection;

@Slf4j
public class SwapStateMachineListener extends StateMachineListenerAdapter<SwapStates, SwapEvents> {

    @Override
    public void stateEntered(State<SwapStates, SwapEvents> state) {
        Collection<State<SwapStates, SwapEvents>> collection = state.getStates();
        StringBuilder stringBuilder = new StringBuilder("");
        collection.forEach(e -> {
            stringBuilder.append(e.getId().name() + " , ");
        });
        log.info(">>> 进入 {}", stringBuilder.toString());
    }

    @Override
    public void stateExited(State<SwapStates, SwapEvents> state) {
        Collection<State<SwapStates, SwapEvents>> collection = state.getStates();
        StringBuilder stringBuilder = new StringBuilder("");
        collection.forEach(e -> {
            stringBuilder.append(e.getId().name() + " , ");
        });
        log.info("<<<  退出 {}", stringBuilder.toString());
    }
}
